package net.piggy.web.mapper;

import net.piggy.model.agg.SecurityUser;
import net.piggy.model.dto.Query;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;


public interface SecurityMapper {
	@Select("select id,username,password,enabled from a_piggy_user where username = #{username}")
    SecurityUser findUserByName(@Param("username")String username);

	@Select("SELECT GROUP_CONCAT(distinct authority) FROM a_piggy_user a " +
			"INNER JOIN a_piggy_user_role b ON a.id = b.user_id " +
			"INNER JOIN a_piggy_authority c ON c.role_id = b.role_id WHERE a.username = #{username}")
	String findAuthoritiesByName(@Param("username")String username);

	@Select("SELECT GROUP_CONCAT(DISTINCT role_name) FROM a_piggy_user a " +
			"INNER JOIN a_piggy_user_role b ON a.id = b.user_id " +
			"INNER JOIN a_piggy_role c ON c.id = b.role_id " +
			"WHERE a.username = #{username}")
	String findRolesByName(@Param("username")String username);

	List<Map<String,Object>> selectAuthorities(Query userQuery);
}
